package b3.widget.mail
{
	import b3.model.*;
	import b3.net.ResourceHelper;
	import b3.util.*;
	import b3.widget.basic.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;

	public class MailReceiveDailog extends BasicWidget
	{
		private var message:TextField;
		private var closeButton:BasicButton;
		
		private static var instance:MailDailog;
		
		public function MailReceiveDailog(mail:MailModel)
		{
			super();
			this.anchor = BasicWidget.ANCHOR_MIDDLE_MIDDLE;
			var Bgr:Class = ResourceHelper.getInstance().getClassByName("MessageBoxBgr");
			var bgr:Sprite = new Bgr();
			bgr.mouseChildren = false;
			addChild(bgr);
			
			//标题
			var titleField:TextField = new TextField();
			titleField.selectable = false;
        	titleField.autoSize = TextFieldAutoSize.CENTER;
			titleField.defaultTextFormat = new TextFormat(BFont.fontName, 20, 0xFFFFFF, true);
			titleField.filters = [new GlowFilter(0x00AAFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			titleField.x = this.width / 2;
			titleField.y = 20;
			titleField.text = "收到邮件！";
			addChild(titleField);
			//from 名字
			var fromNameLabel:TextField = new TextField();
        	fromNameLabel.selectable = false;
        	fromNameLabel.autoSize = TextFieldAutoSize.RIGHT;
			fromNameLabel.defaultTextFormat = new TextFormat(BFont.fontName, 16, 0xFFFFFF, true);
			fromNameLabel.filters = [new GlowFilter(0x00AAFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			fromNameLabel.x = 140;
			fromNameLabel.y = 80;
			fromNameLabel.text = "发件人:";
			addChild(fromNameLabel);
			var fromNameTextField:TextField = new TextField();
			fromNameTextField.selectable = false;
			fromNameTextField.defaultTextFormat = new TextFormat(BFont.fontName, 16, 0xFFFFFF, true);
			fromNameTextField.x = 160;
			fromNameTextField.y = 80;
			fromNameTextField.text = mail.fromName;
			fromNameTextField.width = 230;
			fromNameTextField.height = 25;
			addChild(fromNameTextField);
			
			//消息
			var messageLabel:TextField = new TextField();
			messageLabel.selectable = false;
        	messageLabel.autoSize = TextFieldAutoSize.RIGHT;
			messageLabel.defaultTextFormat = new TextFormat(BFont.fontName, 16, 0xFFFFFF, true);
			messageLabel.filters = [new GlowFilter(0x00AAFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			messageLabel.x = 140;
			messageLabel.y = 120;
			messageLabel.text = "留言消息:";
			addChild(messageLabel);
			message = new TextField();
			message.selectable = false;
        	message.wordWrap = true;
        	message.width = 230;
			message.height = 55;
			message.maxChars = 50;
			message.defaultTextFormat = new TextFormat(BFont.fontName, 16, 0xFFFFFF, true);
			message.text = mail.message;
			message.x = 160;
			message.y = 120;
			addChild(message);
			
			//附件
			var attachmentLabel:TextField = new TextField();
			attachmentLabel.selectable = false;
        	attachmentLabel.autoSize = TextFieldAutoSize.RIGHT;
			attachmentLabel.defaultTextFormat = new TextFormat(BFont.fontName, 16, 0xFFFFFF, true);
			attachmentLabel.filters = [new GlowFilter(0x00AAFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			attachmentLabel.x = 140;
			attachmentLabel.y = 190;
			attachmentLabel.text = "附件礼物:";
			addChild(attachmentLabel);
			//物品框
			for (var i:int = 0; i < 3; i++)
			{
				var objectSlot:ObjectSlot = new ObjectSlot();
				objectSlot.x = 160 + i * 75;
				objectSlot.y = 190;
				addChild(objectSlot);
				if (mail.gifts != null && i < mail.gifts.length)
					objectSlot.addOjbect(mail.gifts[i]);
			}
			
			//关闭按钮
			var CloseButton:Class = ResourceHelper.getInstance().getClassByName("CloseButton1");
			closeButton = new BasicButton(CloseButton);
			closeButton.x = 215;
			closeButton.y = 270;
			addChild(closeButton);
			closeButton.addEventListener(MouseEvent.CLICK, onCloseClick);
			this.x = -this.width / 2;
			this.y = -this.height / 2;
		}
		
		public static function getInstance():MailDailog
		{
			if (!instance)
				instance = new MailDailog();
			return instance;
		}
		
		public function onCloseClick(event:Event):void
		{
			close()
		}
		
	}
}